import dt from '@dt/dt'
import req from './req.js'
let send = req.send

function getTime() {
  return new Date().getTime()
}

// 登录
function login() {
  send({ eventType: 3, loginType: 2 })
}

// 批注
function comment(customerId, wordCount) {
  send({ eventType: 5, customerId, wordCount })
}

// 点击查看客户
function onCustomer(customerId) {
  send({ eventType: 17, customerId })
}

// 点击查看跟进
function onFollow(customerId) {
  send({ eventType: 18, customerId })
}

// 客户列表使用的筛选条件
function customerFilter(params) {
  let data = { ...params }
  delete data.current
  delete data.page
  delete data.rows
  delete data.roleId
  delete data.userId
  delete data.buildingId
  delete data.userCustomerId
  delete data.hasAttention
  let keys = []
  Object.keys(data).forEach(key => {
    if (data[key] != null && data[key] != '') {
      keys.push(key)
    }
  })
  let searchConditions = keys.join('|')
  if (searchConditions) {
    send({
      eventType: 19,
      searchConditions
    })
  }
}

// 认购单审核完成时间
let subscriptionAudit = {
  time: dt.session.get('stats_subscriptionAudit'),
  start: () => {
    subscriptionAudit.time = getTime()
    dt.session.set('stats_subscriptionAudit', subscriptionAudit.time)
  },
  end: () => {
    send({ eventType: 20, launchTimestamp: subscriptionAudit.time })
  }
}

// 签约单审核完成时间
let contractAudit = {
  time: dt.session.get('stats_contractAudit'),
  start: () => {
    contractAudit.time = getTime()
    dt.session.set('stats_contractAudit', contractAudit.time)
  },
  end: () => {
    send({ eventType: 21, launchTimestamp: contractAudit.time })
  }
}

dt.stats = {
  login,
  comment,
  onCustomer,
  onFollow,
  customerFilter,
  subscriptionAudit,
  contractAudit
}
